package com.service;



import com.domain.Global_data;
import com.utilus.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.*;


@Service
public class Public_funtion {


    @Autowired
    private Global_data global_data;

    public List<List<List<String>>> LML_to_LLLS(List<Map<String,Object>> list)
    {
        List<List<List<String>>> LLLS = new ArrayList();
        for(int f = 0;f<list.size();f++)

        {
            Map<String, Object> MSO = list.get(f);
            List<List<String>> LLS = new ArrayList();
            String value = "";

            for (String key : MSO.keySet()) {
                Object valued = MSO.get(key);
                List<String> LS = new ArrayList();
                LS.add(key);
                if (valued == null) {
                    value = "";
                } else {
                    value = valued.toString();

                    LS.add(value);
                }
                System.out.println(key + "  " + value);
                LLS.add(LS);
            }
            LLLS.add(LLS);
        }
        return LLLS;
    }


    public AjaxResult toAjax(int rows)
    {
        if(rows > 0)
            return AjaxResult.success();
        return AjaxResult. error();
    }


//    public void wechat_num_hour_add()
//    {
//        int num;
//        num=global_data.getWechat_num_hour();
//        num++;
//        global_data.setWechat_num_hour(num);
//    }
//    public void wechat_num_day_add()
//    {
//        int num;
//        num=global_data.getWechat_num_day();
//        num+=global_data.getWechat_num_hour();
//        global_data.setWechat_num_day(num);
//    }
//    public void wechat_num_day_clear()
//    {
//        global_data.setWechat_num_hour(0);
//        global_data.setWechat_num_day(0);
//    }
//    public void wechat_chat_day_add()
//    {
//        int num;
//        num=global_data.getWechat_chat_day();
//        num++;
//        global_data.setWechat_chat_day(num);
//    }
//    public void wechat_key_day_add()
//    {
//        int num;
//        num=global_data.getWechat_key_day();
//        num++;
//        global_data.setWechat_key_day(num);
//    }
//

    public  byte[] toByteArray(String hexString) {

        if(hexString.isEmpty())
        {return  null   ;}
        byte[] byteArray = new byte[hexString.length()];
        for (int i = 0; i < byteArray.length; i++) {
            byteArray[i] = (byte) (hexString.charAt(i) );
        }
        return byteArray;
    }

    public void print_log(String logs,int grade)
    {
        if(grade<global_data.getLog_Grade())
        {
            System.out.println(logs);
            String web_log=global_data.getLog();
            web_log=web_log+logs;
            int log_len=web_log.length();
            if(log_len>20000)
            {
                web_log=web_log.substring(5000,log_len);
            }
            global_data.setLog(web_log);
        }
    }
//    public String get_token ()
//    {
//        String token="null";
//        token=get_rember.get_token_for_mysql();
//        return token;
//    }
    public String get_DATE_String_YYmmdd ()
    {
        SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date now = new Date();
        String timestr = inputFormat.format(now);
        return timestr;
    }
    public String get_DATE_String_HHmmss ()
    {
        SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date now = new Date();
        String timestr = inputFormat.format(now);
        return timestr;
    }
    public long getLongData()
    {
        SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss:SSS");
        String inVal= new SimpleDateFormat("yyyy-MM-dd hh:mm:ss:SSS").format(new Date());
        Date date = null;
        try {
            date = inputFormat.parse(inVal);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return date.getTime();
    }




    public int Get_Random()
    {
        Date date = new Date();
        SimpleDateFormat ss= new SimpleDateFormat("ss");
        SimpleDateFormat mm= new SimpleDateFormat("mm");
        String sss=ss.format(date);
        String smm=mm.format(date);
        String sms=smm+sss;
        Random r = new Random(Integer.valueOf(sms));

        int ran1 = r.nextInt(89999999);
        ran1+=10000000;
        System.out.println("产生的8位随机数为："+ran1);
        return ran1;
    }


    public String json_to_url_parameter (String str)
    {
        str=str.replaceAll("\"","");
        str=str.replaceAll(":","=");
        str=str.replaceAll(",","&");
        str=str.replaceAll("\\{","");
        str=str.replaceAll("}","");
        return str;
    }

    public  String sql_null_selsect(String name, String value)
    {

        if(value.isEmpty()){return "";}
        else if(value.equals("null")){return "";}
        else if(value.equals("-1")){return "";}
        else
        {
            return "  AND  "+ name+"   LIKE   '"+value+"'  ";
        }
    }


}
